package bird.spring.com.designpattern.RoomDemo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by co-mall on 2015/12/7.
 */
public class MyMediator {

    List<Room> mRooms = new ArrayList<Room>();

    public MyMediator() {
        for (int i = 0; i < 5; i++) {
            mRooms.add(new Room(14 + i, (14 + i) * 150));
        }
    }
    public Room rentOut(float  area, float  price,float diffPrice,float diffArea) {
        for (Room room : mRooms) {
            if (isSuitable(area, price,diffPrice,diffArea, room)) {
                return  room;
            }
        }
        return null;
    }

    private boolean isSuitable(float area, float price,float diffPrice,float diffArea, Room room) {
        return Math.abs(room.price - price) < diffPrice
                && Math.abs(room.area - area) < diffPrice;
    }
}
